﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Avif2jpeg
{
    public partial class OutputForm : Form
    {
        public OutputForm()
        {
            
            txtOutput = new RichTextBox();
            InitializeComponent();
            this.Shown += (s, e) => { this.txtOutput.ScrollToCaret(); };
        }



        // 添加文本到输出区域（线程安全）
        public void AppendText(string text, Color? color = null)
        {
            if (this.txtOutput.InvokeRequired)
            {
                this.Invoke((Action<string, Color?>)AppendText, text, color);
                return;
            }

            Color textColor = color ?? this.txtOutput.ForeColor;
            this.txtOutput.SelectionStart = this.txtOutput.TextLength;
            this.txtOutput.SelectionColor = textColor;
            this.txtOutput.AppendText($"{DateTime.Now:HH:mm:ss.fff} - {text}{Environment.NewLine}");
            this.txtOutput.ScrollToCaret();
        }

        // 清空输出
        public void ClearOutput()
        {
            if (this.txtOutput.InvokeRequired)
            {
                this.Invoke((Action)ClearOutput);
                return;
            }

            this.txtOutput.Clear();
        }


    }
}
